package com.lagou.work.task03.angel.jobService.impl.dome;

import com.lagou.work.task03.angel.jobService.serverService.JobServerBase;
import com.lagou.work.task03.angel.utils.IOUtil;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.PrintStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author：dingyuan
 * @date：2022.4.5 19:46
 * @description：继承 server端功能抽象类，自定义实现分布式计算server端功能
 */
public class JobServerBaseDemo2 extends JobServerBase {

    private static final String FIEL_END_NAME = ".txt";

    // 启动serverJob
    public static void main(String[] args) throws Exception {

        new JobServerBaseDemo2().run(8888);

    }
    @Override
    public void handleJob(ServerSocket serverSocket) throws Exception {
        InputStream inputStream = null;
        PrintStream printStream = null;
        ByteArrayOutputStream byteArrOutStream = null;
        Socket accept = null;
        try {
            while (true) {
                // 接收来自client端发生的计算任务(此次job是接收一个远程客户端通过mster角色发送的一个排序计算类)
                System.out.println("Server端等待" + "Master端" + "连接请求...");
                accept = serverSocket.accept();
                System.out.println("Master端" + accept.getInetAddress() + "连接成功，等待发送信息...");
                new Thread(new ServerTaskRunnable(accept, "2")).start();
            }

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            IOUtil.close(null,serverSocket);
        }
    }
}
